﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenMms.Common.Auth;
using OpenMms.Domain.Interface.User;
using OpenMms.Domain.RequestModels;
using Microsoft.AspNetCore.Mvc;

namespace OpenMms.MVC.Areas.User.Controllers
{
    /// <summary>
    /// 修改密码
    /// </summary>
    [Area("User")]
    public class ModifyPasswordController : BaseController
    {

        private IModifyPwdService _service;

        public ModifyPasswordController(IAuth auth, IModifyPwdService service) : base(auth)
        {
            this._service = service;
        }
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index() => View();
        /// <summary>
        /// 修改密码操作
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<JsonResult> Modify(ModifyPwdReq req)
        {
            req.UserCode = _auth.GetCurrentUser().Account;
            return Json(await _service.ModifyPwd(req));
        }
    }
}